# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=quantlib
_srcname=QuantLib
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.18
pkgrel=1
pkgdesc="QuantLib - A free/open-source library for quantitative finance (mingw-w64)"
arch=('any')
url="https://www.quantlib.org/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-boost")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs' 'strip')
source=("${_realname}-${pkgver}.tar.gz"::"https://dl.bintray.com/quantlib/releases/${_srcname}-${pkgver}.tar.gz"
        "no-undefined.patch")
sha256sums=('d5048e14f2b7ea79f0adee08b2cbcee01b57b9cc282f60225ff4fcfc614c7ebc'
            'e391fb490928fdf761c7dbb2ca4631d1ccbb092045de50b89fe37a1c5b9787e5')

prepare() {
  cd "${srcdir}/${_srcname}-${pkgver}"
  patch -p1 -i "${srcdir}/no-undefined.patch"

  ./autogen.sh
}

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  ../${_srcname}-${pkgver}/configure \
    --disable-dependency-tracking \
    --enable-static \
    --enable-shared \
    --enable-intraday \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST}
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  install -Dm644 ${srcdir}/${_srcname}-${pkgver}/LICENSE.TXT "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}/LICENSE
}
